package com.sphd.restaurantsystem.model;


import com.android.volley.VolleyError;
import com.sphd.restaurantsystem.info.StaffInfo;
import com.sphd.restaurantsystem.interfaces.VolleyJsonObjectCallBack;
import com.sphd.restaurantsystem.presenter.StaffPresenterImpl;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Hu on 2016/12/22
 */

public class StaffModelImpl implements StaffModel {

    @Override
    public void sendUrl(String url, StaffPresenterImpl staffPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    List<StaffInfo> staffInfoList = JsonUtil.getListFromString(response.getString("res"), StaffInfo.class);
                    staffPresenter.recList(staffInfoList);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
            staffPresenter.sendError(error);
            }
        });
    }

    @Override
    public void delUrl(String url, StaffPresenterImpl staffPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    int res =response.getInt("res");
                        staffPresenter.recRes(res);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
            staffPresenter.sendError(error);
            }
        });
    }
}